package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.dto.ShopDTO;
import com.ibeeking.found.open.api.common.param.AppletsQrCodeParam;
import com.ibeeking.found.open.api.feign.SystemFeignClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.Response;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class SystemFeignFallbackFactory implements FallbackFactory<SystemFeignClient> {
    @Override
    public SystemFeignClient create(Throwable throwable) {
        return new SystemFeignClient() {

            @Override
            public ResponseResult<ShopDTO> queryByShopCode(String shopCode) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据商户编码查询商户信息失败。", null);
            }

            @Override
            public ResponseResult<List<ShopDTO>> queryByShopCodes(List<String> shopCodes) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据商户编码查询商户信息失败。", Collections3.emptyList());
            }

            @Override
            public Response createSceneQR(AppletsQrCodeParam param) {
                return null;
            }
        };
    }
}
